using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Arrow : MonoBehaviour
{
    private bool isTouch;
    private Vector2 startPos;
    [HideInInspector] public Weapon weapon;

    public float destoryDistance;
    public float speed = 7;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.TryGetComponent(out IDamageable damageable))
        {
            damageable.GetDamage(weapon.attackDamage);
            Destroy(gameObject);
        }
    }

    private void Move()
    {
        if (!isTouch)
        {
            transform.Translate(Vector3.right * speed * Time.deltaTime);
        }
        if ((transform.position - (Vector3)startPos).magnitude >= destoryDistance)
        {
            Destroy(gameObject);
        }
    }

    private void Update()
    {
        Move();
    }
}
